﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Entities.ScreeningTool;
using System.Collections.Generic;

// Until a complete redesign of the research states and research products functionality,
// having all the related code in one file is a quick and dirty solution to prevent changes only in a few places

namespace Sustainalytics.ClientDW.Entities
{
    public partial class CorporateData
    {
        public PUResearch ComprehensiveEsgResearchState { get; set; }
        public PUResearch CoreEsgResearchState { get; set; }
        public PUResearch RiskRatingResearchState { get; set; }
        public PUResearch CoreRiskResearchState { get; set; }
        public PUResearch ProductInvolvementResearchState { get; set; }
        public PUResearch GccsResearchState { get; set; }
        public PUResearch CorporateGovernanceResearchState { get; set; }
        public PUResearch ControversyResearchState { get; set; }
        public PUResearch CarbonResearchState { get; set; }
        public PUResearch SolutionsResearchState { get; set; }
    }
}

namespace Sustainalytics.BusinessResearchProductStates.Entities.ResearchState
{
    public partial class CompanyProfileResearchState
    {
        public PUResearch ComprehensiveEsgResearchState { get; set; }
        public PUResearch CoreEsgResearchState { get; set; }
        public PUResearch RiskRatingResearchState { get; set; }
        public PUResearch CoreRiskResearchState { get; set; }
        public PUResearch ProductInvolvementResearchState { get; set; }
        public PUResearch GccsResearchState { get; set; }
        public PUResearch CorporateGovernanceResearchState { get; set; }
        public PUResearch ControversyResearchState { get; set; }
        public PUResearch CarbonResearchState { get; set; }
        public PUResearch SolutionsResearchState { get; set; }
    }
}

namespace Sustainalytics.Entities.ScreeningTool
{
    public class ResearchStates
    {
        [BsonRepresentation(BsonType.String)] public ResearchState ComprehensiveEsg { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState CoreEsg { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState RiskRating { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState CoreRiskRating { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState ProductInvolvement { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState Gccs { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState CorporateGovernance { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState Controversy { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState Carbon { get; set; }
        [BsonRepresentation(BsonType.String)] public ResearchState Solutions { get; set; }
    }

    public static class CorporateDataExtensions
    {
        public static ResearchStates ToResearchStates(this CorporateData corporateData, ClientFacingProduct clientFacingProduct) => new ResearchStates
        {
            ComprehensiveEsg = corporateData.ComprehensiveEsgResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            CoreEsg = corporateData.CoreEsgResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            RiskRating = corporateData.RiskRatingResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            CoreRiskRating = corporateData.CoreRiskResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            ProductInvolvement = corporateData.ProductInvolvementResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            Gccs = corporateData.GccsResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            CorporateGovernance = corporateData.CorporateGovernanceResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            Controversy = corporateData.ControversyResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            Carbon = corporateData.CarbonResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct),
            Solutions = corporateData.SolutionsResearchState.GetResearchStateForClientFacingProduct(clientFacingProduct)
        };
    }
}

namespace Sustainalytics.Entities
{
    public enum ResearchProduct
    {
        Comprehensive,
        Core,
        RiskRating,
        CoreRiskRating,
        ProductInvolvement,
        GlobalCompact,
        CorporateGovernance,
        Controversy,
        Carbon,
        Solutions,
    }

    public static class ResearchProductsExtensions
    {
        public static Dictionary<ResearchProduct, ResearchState> MapToResearchProducts(this ResearchStates researchStates)
            => new Dictionary<ResearchProduct, ResearchState>
            {
                { ResearchProduct.Comprehensive,       researchStates.ComprehensiveEsg    },
                { ResearchProduct.Core,                researchStates.CoreEsg             },
                { ResearchProduct.RiskRating,          researchStates.RiskRating          },
                { ResearchProduct.CoreRiskRating,      researchStates.CoreRiskRating      },
                { ResearchProduct.ProductInvolvement,  researchStates.ProductInvolvement  },
                { ResearchProduct.GlobalCompact,       researchStates.Gccs                },
                { ResearchProduct.CorporateGovernance, researchStates.CorporateGovernance },
                { ResearchProduct.Controversy,         researchStates.Controversy         },
                { ResearchProduct.Carbon,              researchStates.Carbon              },
                { ResearchProduct.Solutions,           researchStates.Solutions           },
            };
    }
}
